﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO_MechSys;
using BLL_MechSys;

namespace FORMS_MechSys
{
    public partial class frmPersonalizar : Form
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmPersonalizar));

        bool CorPrincipal, CorFundo, CorLetras, CorDataGrid, aviso32;
        BLLCor bllCor = new BLLCor();
        DTOCor dtoCorPrincipal = new DTOCor();
        DTOCor dtoCorFundo = new DTOCor();
        DTOCor dtoCorLetra = new DTOCor();
        DTOCor dtoCorDataGrid = new DTOCor();

        BLLPropaganda bllPropaganda = new BLLPropaganda();
        DTOPropaganda dtoPropaganda = new DTOPropaganda();

        
        

        public frmPersonalizar()
        {
            InitializeComponent();
            btn_cadastrar_Click(null, null);
            SetColors();
        }

        private void SetColors()
        {
            dtoCorPrincipal = bllCor.Buscar("Principal");
            dtoCorFundo = bllCor.Buscar("Fundo");
            dtoCorLetra = bllCor.Buscar("Letra");
            dtoCorDataGrid = bllCor.Buscar("DataGrid");
            btn2.BackColor =
                btn3.BackColor = btn4.BackColor = btn5.BackColor = btn6.BackColor =tlpMenuStripRigth.BackColor = btnSair.BackColor =
                btn7.BackColor = btn77.BackColor = tlpbarraleft.BackColor = tlpbarraEsquerda.BackColor = btnSalvarBemVindo.BackColor =
                btnCorDataGrid.BackColor = tlpMenuStripCenter.BackColor = tlpMenuStripLeft.BackColor =  
                btnBemVindo.BackColor = btnCores.BackColor = btnCorFundo.BackColor = pictureBox38.BackColor =
                btnCorLetras.BackColor = btnEscolherCor.BackColor = btnPropagandas.BackColor = btnSalvar.BackColor = pictureBox39.BackColor =
                btnAddPropaganda.BackColor = btnEditarPropaganda.BackColor = btnExcluirPropaganda.BackColor = btnUpPropaganda.BackColor =
                btnDownPropaganda.BackColor = btnSalvarPropagandas.BackColor = btnProcurarImagem.BackColor = pictureBox34.BackColor =
                pictureBox35.BackColor = pictureBox36.BackColor = pictureBox37.BackColor = pictureBox40.BackColor = pictureBox41.BackColor =
                pictureBox42.BackColor = pictureBox43.BackColor = lblFuncionario.ForeColor = tlpBemVindoMenuLateral.BackColor =                
                tlpBemVindoPrincipal.BackColor = dtoCorPrincipal.Cor;
            this.BackColor = tlpMenuStrip.BackColor = tlpPrincipal.BackColor =dtoCorFundo.Cor;
            btnCorDataGrid.ForeColor = label1.ForeColor =  
                 btnBemVindo.ForeColor = btnCores.ForeColor = btnCorFundo.ForeColor =
                btnCorLetras.ForeColor = btnEscolherCor.ForeColor = btnPropagandas.ForeColor = btnSalvar.ForeColor =
                btn2.ForeColor = btn3.ForeColor = btn4.ForeColor = btn5.ForeColor = lblFuncionario.ForeColor =
                btn6.ForeColor = btn7.ForeColor = btn77.ForeColor = tlpbarraleft.ForeColor = label6.ForeColor =
                dtoCorLetra.Cor;
             dgvPropagandas.BackgroundColor = dtoCorDataGrid.Cor;

            VisualizarCorDataGrid(dtoCorDataGrid.Cor);
            VisualizarCorfundo(dtoCorFundo.Cor);
            VisualizarCorLetras(dtoCorLetra.Cor);
            VisualizarCorPrincipal(dtoCorPrincipal.Cor);

        }

        private void Recolher()
        {

        }

        private void Expandir(string botao)
        {
            this.tlpPrincipal.RowStyles[0] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 15F));
            this.tlpPrincipal.RowStyles[1] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 0F));
            this.tlpPrincipal.RowStyles[2] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 0F));
            this.tlpPrincipal.RowStyles[3] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 0F));
            this.tlpPrincipal.RowStyles[4] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 0F));
            this.tlpPrincipal.RowStyles[5] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 0F));
            this.tlpPrincipal.RowStyles[6] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 0F));
            this.tlpPrincipal.RowStyles[7] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 15F));
            groupBox1.Visible = false;
            tlpmenu.Visible = false;


            gpbPropagandas.Visible = false;

            switch (botao)
            {
                case "Cores":
                    tlpCores.Visible = true;
                    groupBox1.Visible = true;

                    this.tlpPrincipal.RowStyles[6] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
                    tlpmenu.Visible = true;
                    this.tlpPrincipal.RowStyles[1] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 100F));

                    break;
                case "Propagandas":
                    tlpCores.Visible = true;
                    gpbPropagandas.Visible = true;
                    this.tlpPrincipal.RowStyles[2] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 185F));
                    this.tlpPrincipal.RowStyles[6] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
                    this.WindowState = FormWindowState.Maximized;
                    tlpmenu.Visible = true;
                    
                    break;
                case "BemVindo":
                    tlpBemVindo.Visible = true;
                    this.tlpPrincipal.RowStyles[2] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 125F));
                    this.tlpPrincipal.RowStyles[5] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 240));
                    this.WindowState = FormWindowState.Maximized;

                    break;
            }
        }

        private void VisualizarCorPrincipal(Color cor)
        {
            tlpTitulo.BackColor = cor;
            tlpBarraRight.BackColor = cor;
            tlpbarraleft.BackColor = cor;
            btn77.BackColor = btn2.BackColor = btn3.BackColor = btn4.BackColor = btn5.BackColor = btn6.BackColor = btn7.BackColor = btn8.BackColor = btn9.BackColor = btn11.BackColor = btn12.BackColor = cor;
            pctlogo.BackColor = cor;

        }

        private void VisualizarCorfundo(Color cor)
        {
            tlpMenuPrincipalMini.BackColor = cor;
        }

        private void VisualizarCorLetras(Color cor)
        {
            btn2.ForeColor = btn2.ForeColor = btn3.ForeColor = btn4.ForeColor = btn5.ForeColor = btn6.ForeColor =
                btn7.ForeColor = btn77.ForeColor =
            lbl1.ForeColor = lbl2.ForeColor = lbl3.ForeColor = lbl4.ForeColor = lbl5.ForeColor = cor;
        }


        private void VisualizarCorDataGrid(Color cor)
        {
            dtg1.BackgroundColor = dtg2.BackgroundColor = dtg3.BackgroundColor = dtg4.BackgroundColor = cor;
        }

        private void btn_cadastrar_Click(object sender, EventArgs e)
        {
            Expandir("Cores");
            LoadPropagandas();
            btnEscolherCor_Click(null, null);
        }

        private void btnCor23_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor23.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor23.BackColor);
            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor23.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor23.BackColor);
        }

        private void btnCor13_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor13.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor13.BackColor);
            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor13.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor13.BackColor);

        }

        private void btnCor47_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor47.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor47.BackColor);
            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor47.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor47.BackColor);

        }

        private void btnCor48_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor48.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor48.BackColor);
            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor48.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor48.BackColor);

        }

        private void btnCor14_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor14.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor14.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor14.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor14.BackColor);
        }

        private void btnCor2_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor2.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor2.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor2.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor2.BackColor);
        }

        private void btnCor3_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor3.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor3.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor3.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor3.BackColor);
        }

        private void btnCor15_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor15.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor15.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor15.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor15.BackColor);
        }

        private void btnCor25_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor25.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor25.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor25.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor25.BackColor);
        }

        private void btnCor26_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor26.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor26.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor26.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor26.BackColor);
        }

        private void btnCor16_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor16.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor16.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor16.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor16.BackColor);
        }

        private void btnCor4_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor4.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor4.BackColor);


            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor4.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor4.BackColor);

        }

        private void btnCor5_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor5.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor5.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor5.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor5.BackColor);
        }

        private void btnCor17_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor17.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor17.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor17.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor17.BackColor);
        }

        private void btnCor27_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor27.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor27.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor27.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor27.BackColor);
        }

        private void btnCor28_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor28.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor28.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor28.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor28.BackColor);
        }

        private void btnCor18_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor18.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor18.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor18.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor18.BackColor);
        }

        private void btnCor6_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor6.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor6.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor6.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor6.BackColor);
        }

        private void btnCor7_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor7.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor7.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor7.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor7.BackColor);
        }

        private void btnCor19_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor19.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor19.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor19.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor19.BackColor);
        }

        private void btnCor29_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor29.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor29.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor29.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor29.BackColor);
        }

        private void btnCor30_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor30.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor30.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor30.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor30.BackColor);
        }

        private void btnCor20_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor20.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor20.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor20.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor20.BackColor);
        }

        private void btnCor8_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor8.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor8.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor8.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor8.BackColor);
        }

        private void btnCor9_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor9.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor9.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor9.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor9.BackColor);
        }

        private void btnCor21_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor21.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor21.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor21.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor21.BackColor);
        }

        private void btnCor31_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor31.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor31.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor31.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor31.BackColor);
        }

        private void btnCor32_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor32.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor32.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor32.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor32.BackColor);
        }

        private void btnCor22_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor22.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor22.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor22.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor22.BackColor);
        }

        private void btnCor10_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor10.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor10.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor10.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor10.BackColor);
        }

        private void btnCor11_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor11.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor11.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor11.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor11.BackColor);
        }

        private void btnCor1_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor1.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor1.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor1.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor1.BackColor);
        }

        private void btnCor34_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor34.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor34.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor34.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor34.BackColor);
        }

        private void btnCor24_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor24.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor24.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor24.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor24.BackColor);
        }

        private void btnCor12_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor12.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor12.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor12.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor12.BackColor);
        }

        private void btnCor37_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor37.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor37.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor37.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor37.BackColor);
        }

        private void btnCor41_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor41.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor41.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor41.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor41.BackColor);
        }

        private void btnCor35_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor35.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor35.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor35.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor35.BackColor);
        }

        private void btnCor36_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor36.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor36.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor36.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor36.BackColor);
        }

        private void btnCor42_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor42.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor42.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor42.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor42.BackColor);
        }

        private void btnCor38_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor38.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor38.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor38.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor38.BackColor);
        }

        private void btnCor39_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor39.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor39.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor39.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor39.BackColor);
        }

        private void btnCor43_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor43.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor43.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor43.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor43.BackColor);
        }

        private void btnCor45_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor45.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor45.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor45.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor45.BackColor);
        }

        private void btnCor46_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor46.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor46.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor46.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor46.BackColor);
        }

        private void btnCor44_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor44.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor44.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor44.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor44.BackColor);
        }

        private void btnCor40_Click(object sender, EventArgs e)
        {
            if (CorPrincipal)
                VisualizarCorPrincipal(btnCor40.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnCor40.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnCor40.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnCor40.BackColor);
        }

        private void btnPesquisaCor_Click(object sender, EventArgs e)
        {
            colorDialog1.ShowDialog();
            btnPesquisaCor.BackColor = colorDialog1.Color;

            if (CorPrincipal)
                VisualizarCorPrincipal(btnPesquisaCor.BackColor);
            else if (CorFundo)
                VisualizarCorfundo(btnPesquisaCor.BackColor);

            else if (CorDataGrid)
                VisualizarCorDataGrid(btnPesquisaCor.BackColor);
            else if (CorLetras)
                VisualizarCorLetras(btnPesquisaCor.BackColor);

        }

        private void btnCorLetras_Click(object sender, EventArgs e)
        {
            CorLetras = RestaurarComponentes();
            btnCorLetras.Text = btnCorLetras.Text.ToUpper();
        }

        private void btnCorDataGrid_Click(object sender, EventArgs e)
        {
            CorDataGrid = RestaurarComponentes();
            btnCorDataGrid.Text = btnCorDataGrid.Text.ToUpper();
        }

        private void btnEscolherCor_Click(object sender, EventArgs e)
        {
            CorPrincipal = RestaurarComponentes();
            btnEscolherCor.Text = btnEscolherCor.Text.ToUpper();
        }

        private void btnCorFundo_Click(object sender, EventArgs e)
        {
            CorFundo = RestaurarComponentes();
            btnCorFundo.Text = btnCorFundo.Text.ToUpper();
        }

        private bool RestaurarComponentes()
        {
            CorDataGrid = false;
            CorFundo = false;
            CorLetras = false;
            CorPrincipal = false;

            btnCorFundo.Text = "Fundo";
            btnCorDataGrid.Text = "DataGrid";
            btnCorLetras.Text = "Letras";
            btnEscolherCor.Text = "Principal";

            return true;

        }

        private void btnSalvar_Click(object sender, EventArgs e)
        {
            DTOCor AlterarCor = new DTOCor();
            AlterarCor.Componente = "Fundo";
            AlterarCor.R = tlpMenuPrincipalMini.BackColor.R;
            AlterarCor.G = tlpMenuPrincipalMini.BackColor.G;
            AlterarCor.B = tlpMenuPrincipalMini.BackColor.B;
            AlterarCor.FuncionarioID = BLLUtilitarios.FuncionarioLogadoID;
            bllCor.Atualizar(AlterarCor);

            AlterarCor.Componente = "Principal";
            AlterarCor.R = tlpTitulo.BackColor.R;
            AlterarCor.G = tlpTitulo.BackColor.G;
            AlterarCor.B = tlpTitulo.BackColor.B;
            AlterarCor.FuncionarioID = BLLUtilitarios.FuncionarioLogadoID;
            bllCor.Atualizar(AlterarCor);

            AlterarCor.Componente = "Letra";
            AlterarCor.R = lbl1.ForeColor.R;
            AlterarCor.G = lbl1.ForeColor.G;
            AlterarCor.B = lbl1.ForeColor.B;
            AlterarCor.FuncionarioID = BLLUtilitarios.FuncionarioLogadoID;
            bllCor.Atualizar(AlterarCor);

            AlterarCor.Componente = "DataGrid";
            AlterarCor.R = dtg2.BackgroundColor.R;
            AlterarCor.G = dtg2.BackgroundColor.G;
            AlterarCor.B = dtg2.BackgroundColor.B;
            AlterarCor.FuncionarioID = BLLUtilitarios.FuncionarioLogadoID;
            bllCor.Atualizar(AlterarCor);
            SetColors();
        }

        private void linkRestaurar_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            VisualizarCorPrincipal(System.Drawing.Color.FromArgb(((int)(((byte)(111)))), ((int)(((byte)(113)))), ((int)(((byte)(126))))));
            VisualizarCorfundo(System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240))))));
            VisualizarCorLetras(System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255))))));
            VisualizarCorDataGrid(System.Drawing.Color.FromArgb(((int)(((byte)(111)))), ((int)(((byte)(113)))), ((int)(((byte)(126))))));
        }


        //
        //enter
        //
        private void btnCoreskkkkkkk(object sender, EventArgs e)
        {
            btnCores.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(224)))), ((int)(((byte)(255)))));
            btnCores.ForeColor = Color.Black;
            this.btnCores.BackgroundImage = ((System.Drawing.Image)(null));

        }

        private void btnPropagandaskkkkkkk(object sender, EventArgs e)
        {
            btnPropagandas.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(224)))), ((int)(((byte)(255)))));
            btnPropagandas.ForeColor = Color.Black;
            this.btnPropagandas.BackgroundImage = ((System.Drawing.Image)(null));

        }

        private void btnBarrasLateraiskkkkkkk(object sender, EventArgs e)
        {
            btnBemVindo.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(224)))), ((int)(((byte)(255)))));
            btnBemVindo.ForeColor = Color.Black;
            this.btnBemVindo.BackgroundImage = ((System.Drawing.Image)(null));

        }


        private void btnEscolherCorkkkkkkk(object sender, EventArgs e)
        {
            btnEscolherCor.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(224)))), ((int)(((byte)(255)))));
            btnEscolherCor.ForeColor = Color.Black;
            this.btnEscolherCor.BackgroundImage = ((System.Drawing.Image)(null));

        }

        private void btnCorFundokkkkkkk(object sender, EventArgs e)
        {
            btnCorFundo.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(224)))), ((int)(((byte)(255)))));
            btnCorFundo.ForeColor = Color.Black;
            this.btnCorFundo.BackgroundImage = ((System.Drawing.Image)(null));

        }

        private void btnCorLetraskkkkkkk(object sender, EventArgs e)
        {
            btnCorLetras.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(224)))), ((int)(((byte)(255)))));
            btnCorLetras.ForeColor = Color.Black;
            this.btnCorLetras.BackgroundImage = ((System.Drawing.Image)(null));

        }

        private void btnCorDataGridkkkkkkk(object sender, EventArgs e)
        {
            btnCorDataGrid.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(224)))), ((int)(((byte)(255)))));
            btnCorDataGrid.ForeColor = Color.Black;
            this.btnCorDataGrid.BackgroundImage = ((System.Drawing.Image)(null));

        }

        private void btnSalvarkkkkkkk(object sender, EventArgs e)
        {
            btnSalvar.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(224)))), ((int)(((byte)(255)))));
            btnSalvar.ForeColor = Color.Black;
            this.btnSalvar.BackgroundImage = ((System.Drawing.Image)(null));

        }

        private void btnSalvarBemVindokkkkkkk(object sender, EventArgs e)
        {
            btnSalvarBemVindo.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(224)))), ((int)(((byte)(255)))));
            btnSalvarBemVindo.ForeColor = Color.Black;

        }

        
        //
        //leave
        //
        private void btnSalvarBemVindo_MouseLeave(object sender, EventArgs e)
        {
            btnSalvarBemVindo.BackColor = dtoCorPrincipal.Cor;
            btnSalvarBemVindo.ForeColor = dtoCorLetra.Cor;

    
        }

        private void btnBarrasLaterais_MouseLeave(object sender, EventArgs e)
        {
            btnBemVindo.BackColor = dtoCorPrincipal.Cor;
            btnBemVindo.ForeColor = dtoCorLetra.Cor;
            btnBemVindo.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btn00.BackgroundImage")));

        }

        private void btnPropagandas_MouseLeave(object sender, EventArgs e)
        {
            btnPropagandas.BackColor = dtoCorPrincipal.Cor;
            btnPropagandas.ForeColor = dtoCorLetra.Cor;
            btnPropagandas.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btn00.BackgroundImage")));

        }

        private void btnCores_MouseLeave(object sender, EventArgs e)
        {
            btnCores.BackColor = dtoCorPrincipal.Cor;
            btnCores.ForeColor = dtoCorLetra.Cor;
            btnCores.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btn00.BackgroundImage")));

        }

        private void btnSalvar_MouseLeave(object sender, EventArgs e)
        {
            btnSalvar.BackColor = dtoCorPrincipal.Cor;
            btnSalvar.ForeColor = dtoCorLetra.Cor;
            btnSalvar.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btn00.BackgroundImage")));

        }

        private void btnCorDataGrid_MouseLeave(object sender, EventArgs e)
        {
            btnCorDataGrid.BackColor = dtoCorPrincipal.Cor;
            btnCorDataGrid.ForeColor = dtoCorLetra.Cor;
            btnCorDataGrid.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btn00.BackgroundImage")));

        }

        private void btnCorLetras_MouseLeave(object sender, EventArgs e)
        {
            btnCorLetras.BackColor = dtoCorPrincipal.Cor;
            btnCorLetras.ForeColor = dtoCorLetra.Cor;
            btnCorLetras.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btn00.BackgroundImage")));
        }

        private void btnEscolherCor_MouseLeave(object sender, EventArgs e)
        {
            btnEscolherCor.BackColor = dtoCorPrincipal.Cor;
            btnEscolherCor.ForeColor = dtoCorLetra.Cor;
            btnEscolherCor.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btn00.BackgroundImage")));
        }

        private void btnCorFundo_MouseLeave(object sender, EventArgs e)
        {
            btnCorFundo.BackColor = dtoCorPrincipal.Cor;
            btnCorFundo.ForeColor = dtoCorLetra.Cor;
            btnCorFundo.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btn00.BackgroundImage")));
        }

        private void btnProcurarImagem_Click(object sender, EventArgs e)
        {
            try
            {
                if (ofdPropaganada.ShowDialog() == DialogResult.OK)
                {
                    pcbImagem.Visible = true;
                    Image imagem = new Bitmap(new Bitmap(ofdPropaganada.FileName), new Size(Int32.Parse(numLargura.Value.ToString()) * 2, Int32.Parse(numAltura.Value.ToString()) * 2));

                    char[] nome = ofdPropaganada.SafeFileName.ToCharArray();
                    string ShortName = "";
                    for (int i = 0; i < nome.Length; i++)
                    {
                        if (nome[i] == '.')
                            break;
                        else
                            ShortName += nome[i];
                    }
                    string Nome = ShortName;
                    int cont = 2;
                    for (int i = 0; i < dgvPropagandas.Rows.Count; i++)
                    {
                        if (dgvPropagandas[1, i].Value.ToString() == ShortName)
                        {
                            ShortName = Nome + cont;
                            cont++;
                            i = -1;
                        }
                    }
                    txtNomePropaganda.Text = ShortName;
                    btnSalvarPropagandas.Enabled = true;
                    txtNomePropaganda.Enabled = true;
                    txtNomePropaganda.Focus();
                    pcbImagem.Image = imagem;
                    dtoPropaganda.Imagem = imagem;
                }
            }
            catch (Exception)
            {
                throw new Exception("Não foi possível Carregar a Imagem!");
            }
        }

        private void numAltura_ValueChanged(object sender, EventArgs e)
        {
            if (pcbImagem.Image != null)
            {
                Image imagem = new Bitmap(pcbImagem.Image, new Size(Int32.Parse(numLargura.Value.ToString()) * 2, Int32.Parse(numAltura.Value.ToString()) * 2));
                dtoPropaganda.Imagem = imagem;
            }
            this.tlpImagem.RowStyles[1] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, (float)(numAltura.Value)));
        }

        private void numLargura_ValueChanged(object sender, EventArgs e)
        {
            if (pcbImagem.Image != null)
            {
                Image imagem = new Bitmap(pcbImagem.Image, new Size(Int32.Parse(numLargura.Value.ToString()) * 2, Int32.Parse(numAltura.Value.ToString()) * 2));
                dtoPropaganda.Imagem = imagem;
            }
            this.tlpImagem.ColumnStyles[1] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)(numLargura.Value)));
        }

        private void btnSalvarPropagandas_Click(object sender, EventArgs e)
        {

            if (!string.IsNullOrWhiteSpace(txtNomePropaganda.Text))
            {
                dtoPropaganda.Altura = (int)numAltura.Value;
                dtoPropaganda.Largura = (int)numLargura.Value;
                dtoPropaganda.Margem = (int)((40 - (int)numAltura.Value) / 2);
                dtoPropaganda.Imagem = pcbImagem.Image;
                dtoPropaganda.Nome = txtNomePropaganda.Text;
                btnSalvarPropagandas.Enabled = false;
                txtNomePropaganda.Clear();
                txtNomePropaganda.Enabled = false;
                btnProcurarImagem.Enabled = false;
                Image img = null;
                pcbImagem.Image = img;

                if (dtoPropaganda.PropagandaID == 0)
                {
                    dtoPropaganda.Indice = dgvPropagandas.Rows.Count + 1;
                    bllPropaganda.Inserir(dtoPropaganda);
                }
                else
                    bllPropaganda.Atualizar(dtoPropaganda);

                LoadPropagandas();
                PopularGridPropagandas();

            }
            else
                new frmMessageBox().Show("Insira um nome Válido para a imagem.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

        private void dgvPropagandas_DataSourceChanged(object sender, EventArgs e)
        {
            if (dgvPropagandas.Rows.Count > 0)
            {
                btnExcluirPropaganda.Enabled = true;
                //btnSalvarPropagandas.Enabled = true;
                btnEditarPropaganda.Enabled = true;
                btnDownPropaganda.Enabled = true;
                btnUpPropaganda.Enabled = true;
                if (dgvPropagandas.Rows.Count > 32 && !aviso32)
                {
                    new frmMessageBox().Show("O número de propagandas é superior ao limite de 32.\nLimite é o número máximo de exibições possíveis,\n que varia de acordo com as larguras das imagens.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    aviso32 = true;
                }
            }
            else
            {
                btnExcluirPropaganda.Enabled = false;
                btnSalvarPropagandas.Enabled = false;
                btnEditarPropaganda.Enabled = false;
                btnDownPropaganda.Enabled = false;
                btnUpPropaganda.Enabled = false;
            }
        }

        private void PopularGridPropagandas()
        {
            dgvPropagandas.DataSource = bllPropaganda.BuscarPropagandaCadastradosSimples();
        }

        private void LoadPropagandas()
        {
            List<DTOPropaganda> listaPropaganda = new List<DTOPropaganda>();
            listaPropaganda = bllPropaganda.BuscarPropagandaCadastrados();
            for (int i = 0; i < listaPropaganda.Count; i++)
            {
                listaPropaganda[i].Altura = listaPropaganda[i].Altura / 2;
                listaPropaganda[i].Largura = listaPropaganda[i].Largura / 2;
                listaPropaganda[i].Margem = listaPropaganda[i].Margem / 2;
            }

            pictureBox2.Image = pictureBox3.Image = pictureBox4.Image = pictureBox5.Image = pictureBox6.Image = pictureBox7.Image = pictureBox8.Image = pictureBox9.Image =
            pictureBox10.Image = pictureBox11.Image = pictureBox12.Image = pictureBox13.Image = pictureBox14.Image = pictureBox15.Image = pictureBox16.Image = pictureBox17.Image =
            pictureBox18.Image = pictureBox19.Image = pictureBox20.Image = pictureBox21.Image = pictureBox22.Image = pictureBox23.Image = pictureBox24.Image = pictureBox25.Image =
            pictureBox26.Image = pictureBox27.Image = pictureBox28.Image = pictureBox29.Image = pictureBox30.Image = pictureBox31.Image = pictureBox32.Image = pictureBox33.Image = null;



            this.tlpLinhasPropagandas.RowStyles[0] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
            this.tlpLinhasPropagandas.RowStyles[1] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
            this.tlpLinhasPropagandas.RowStyles[2] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
            this.tlpLinhasPropagandas.RowStyles[3] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
            this.tlpLinhasPropagandas.Size = new System.Drawing.Size(741, 0);

            int largDisp = tlpPropagandaLinha1.Size.Width;
            int contPropagandas = 0;

            //primeira Linha
            if (contPropagandas < listaPropaganda.Count)
            {

                tlpPropagandaLinha1.ColumnStyles[1] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha1.ColumnStyles[3] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha1.ColumnStyles[5] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha1.ColumnStyles[7] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha1.ColumnStyles[9] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha1.ColumnStyles[11] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha1.ColumnStyles[13] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);

                this.tlpLinhasPropagandas.RowStyles[0] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 23F));
                this.tlpLinhasPropagandas.Size = new System.Drawing.Size(741, 23);
                for (int i = 0; i < 8; i++)
                {
                    if (contPropagandas == listaPropaganda.Count)
                    {
                        largDisp = -1;
                        contPropagandas--;
                    }
                    if (largDisp < (listaPropaganda[contPropagandas].Largura + 20))
                    {
                        switch (i)
                        {
                            case 0: tlpPropagandaLinha1.ColumnStyles[0] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 1: tlpPropagandaLinha1.ColumnStyles[2] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 2: tlpPropagandaLinha1.ColumnStyles[4] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 3: tlpPropagandaLinha1.ColumnStyles[6] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 4: tlpPropagandaLinha1.ColumnStyles[8] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 5: tlpPropagandaLinha1.ColumnStyles[10] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 6: tlpPropagandaLinha1.ColumnStyles[12] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 7: tlpPropagandaLinha1.ColumnStyles[14] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                        }

                        if (largDisp == -1)
                            contPropagandas++;
                    }
                    else
                    {
                        switch (i)
                        {
                            case 0:
                                tlpPropagandaLinha1.ColumnStyles[0] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha1.ColumnStyles[1] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                pictureBox2.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox2.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 1:
                                tlpPropagandaLinha1.ColumnStyles[1] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha1.ColumnStyles[2] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha1.ColumnStyles[3] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox3.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox3.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 2:
                                tlpPropagandaLinha1.ColumnStyles[3] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha1.ColumnStyles[4] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha1.ColumnStyles[5] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox4.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox4.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 3:
                                tlpPropagandaLinha1.ColumnStyles[5] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha1.ColumnStyles[6] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha1.ColumnStyles[7] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox5.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox5.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 4:
                                tlpPropagandaLinha1.ColumnStyles[7] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha1.ColumnStyles[8] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha1.ColumnStyles[9] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox6.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox6.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 5:
                                tlpPropagandaLinha1.ColumnStyles[9] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha1.ColumnStyles[10] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha1.ColumnStyles[11] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox7.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox7.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 6:
                                tlpPropagandaLinha1.ColumnStyles[11] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha1.ColumnStyles[12] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha1.ColumnStyles[13] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox8.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox8.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 7:
                                tlpPropagandaLinha1.ColumnStyles[14] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha1.ColumnStyles[13] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                pictureBox9.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox9.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                        }
                        largDisp -= listaPropaganda[contPropagandas].Largura;
                        contPropagandas++;
                    }
                }
            }
            largDisp = tlpPropagandaLinha2.Size.Width;


            //Segunda Linha
            if (contPropagandas < listaPropaganda.Count)
            {
                tlpPropagandaLinha2.ColumnStyles[1] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha2.ColumnStyles[3] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha2.ColumnStyles[5] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha2.ColumnStyles[7] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha2.ColumnStyles[9] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha2.ColumnStyles[11] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha2.ColumnStyles[13] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);

                this.tlpLinhasPropagandas.RowStyles[1] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 23F));

                this.tlpLinhasPropagandas.Size = new System.Drawing.Size(741, 46);
                for (int i = 0; i < 8; i++)
                {
                    if (contPropagandas == listaPropaganda.Count)
                    {
                        largDisp = -1;
                        contPropagandas--;
                    }
                    if (largDisp < (listaPropaganda[contPropagandas].Largura + 20))
                    {
                        switch (i)
                        {
                            case 0: tlpPropagandaLinha2.ColumnStyles[0] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 1: tlpPropagandaLinha2.ColumnStyles[2] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 2: tlpPropagandaLinha2.ColumnStyles[4] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 3: tlpPropagandaLinha2.ColumnStyles[6] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 4: tlpPropagandaLinha2.ColumnStyles[8] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 5: tlpPropagandaLinha2.ColumnStyles[10] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 6: tlpPropagandaLinha2.ColumnStyles[12] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 7: tlpPropagandaLinha2.ColumnStyles[14] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                        }
                        if (largDisp == -1)
                            contPropagandas++;
                    }
                    else
                    {
                        switch (i)
                        {
                            case 0:
                                tlpPropagandaLinha2.ColumnStyles[0] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha2.ColumnStyles[1] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox10.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox10.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 1:
                                tlpPropagandaLinha2.ColumnStyles[1] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha2.ColumnStyles[2] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha2.ColumnStyles[3] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox11.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox11.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 2:
                                tlpPropagandaLinha2.ColumnStyles[3] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha2.ColumnStyles[4] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha2.ColumnStyles[5] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox12.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox12.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 3:
                                tlpPropagandaLinha2.ColumnStyles[5] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha2.ColumnStyles[6] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha2.ColumnStyles[7] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox13.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox13.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 4:
                                tlpPropagandaLinha2.ColumnStyles[7] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha2.ColumnStyles[8] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha2.ColumnStyles[9] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox14.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox14.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 5:
                                tlpPropagandaLinha2.ColumnStyles[9] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha2.ColumnStyles[10] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha2.ColumnStyles[11] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox15.Image = listaPropaganda[contPropagandas].Imagem;
                                int a = listaPropaganda[contPropagandas].Indice;
                                pictureBox15.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 6:
                                tlpPropagandaLinha2.ColumnStyles[11] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha2.ColumnStyles[12] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha2.ColumnStyles[13] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox16.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox16.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 7:
                                tlpPropagandaLinha2.ColumnStyles[13] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha2.ColumnStyles[14] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                pictureBox17.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox17.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                        }
                        largDisp -= listaPropaganda[contPropagandas].Largura;
                        contPropagandas++;
                    }
                }
            }
            largDisp = tlpPropagandaLinha3.Size.Width;

            //Terceira Linha
            if (contPropagandas < listaPropaganda.Count)
            {

                tlpPropagandaLinha3.ColumnStyles[1] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha3.ColumnStyles[3] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha3.ColumnStyles[5] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha3.ColumnStyles[7] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha3.ColumnStyles[9] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha3.ColumnStyles[11] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha3.ColumnStyles[13] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);

                this.tlpLinhasPropagandas.RowStyles[2] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 23F));
                this.tlpLinhasPropagandas.Size = new System.Drawing.Size(741, 69);
                for (int i = 0; i < 8; i++)
                {
                    if (contPropagandas == listaPropaganda.Count)
                    {
                        largDisp = -1;
                        contPropagandas--;
                    }
                    if (largDisp < (listaPropaganda[contPropagandas].Largura + 20))
                    {
                        switch (i)
                        {
                            case 0: tlpPropagandaLinha3.ColumnStyles[0] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 1: tlpPropagandaLinha3.ColumnStyles[2] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 2: tlpPropagandaLinha3.ColumnStyles[4] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 3: tlpPropagandaLinha3.ColumnStyles[6] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 4: tlpPropagandaLinha3.ColumnStyles[8] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 5: tlpPropagandaLinha3.ColumnStyles[10] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 6: tlpPropagandaLinha3.ColumnStyles[12] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 7: tlpPropagandaLinha3.ColumnStyles[14] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                        }
                        if (largDisp == -1)
                            contPropagandas++;
                    }
                    else
                    {
                        switch (i)
                        {
                            case 0:
                                tlpPropagandaLinha3.ColumnStyles[0] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha3.ColumnStyles[1] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                pictureBox18.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox18.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 1:
                                tlpPropagandaLinha3.ColumnStyles[1] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha3.ColumnStyles[2] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha3.ColumnStyles[3] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox19.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox19.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 2:
                                tlpPropagandaLinha3.ColumnStyles[3] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha3.ColumnStyles[4] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha3.ColumnStyles[5] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox20.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox20.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 3:
                                tlpPropagandaLinha3.ColumnStyles[5] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha3.ColumnStyles[6] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha3.ColumnStyles[7] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox21.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox21.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 4:
                                tlpPropagandaLinha3.ColumnStyles[7] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha3.ColumnStyles[8] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha3.ColumnStyles[9] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox22.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox22.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 5:
                                tlpPropagandaLinha3.ColumnStyles[9] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha3.ColumnStyles[10] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha3.ColumnStyles[11] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox23.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox23.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 6:
                                tlpPropagandaLinha3.ColumnStyles[11] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha3.ColumnStyles[12] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                pictureBox24.Image = listaPropaganda[contPropagandas].Imagem;
                                tlpPropagandaLinha3.ColumnStyles[13] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox24.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 7:
                                tlpPropagandaLinha3.ColumnStyles[13] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha3.ColumnStyles[14] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                pictureBox25.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox25.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                        }
                        largDisp -= listaPropaganda[contPropagandas].Largura;
                        contPropagandas++;
                    }
                }
            }

            largDisp = tlpPropagandaLinha4.Size.Width;

            //Quarta Linha
            if (contPropagandas < listaPropaganda.Count)
            {

                tlpPropagandaLinha4.ColumnStyles[1] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha4.ColumnStyles[3] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha4.ColumnStyles[5] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha4.ColumnStyles[7] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha4.ColumnStyles[9] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha4.ColumnStyles[11] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha4.ColumnStyles[13] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);

                this.tlpLinhasPropagandas.RowStyles[3] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 23F));
                this.tlpLinhasPropagandas.Size = new System.Drawing.Size(741, 92);
                for (int i = 0; i < 8; i++)
                {
                    if (contPropagandas == listaPropaganda.Count)
                    {
                        largDisp = -1;
                        contPropagandas--;
                    }
                    if (largDisp < (listaPropaganda[contPropagandas].Largura + 20))
                    {
                        switch (i)
                        {
                            case 0: tlpPropagandaLinha4.ColumnStyles[0] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 1: tlpPropagandaLinha4.ColumnStyles[2] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 2: tlpPropagandaLinha4.ColumnStyles[4] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 3: tlpPropagandaLinha4.ColumnStyles[6] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 4: tlpPropagandaLinha4.ColumnStyles[8] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 5: tlpPropagandaLinha4.ColumnStyles[10] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 6: tlpPropagandaLinha4.ColumnStyles[12] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 7: tlpPropagandaLinha4.ColumnStyles[14] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                        }
                        if (largDisp == -1)
                            contPropagandas++;
                    }
                    else
                    {
                        switch (i)
                        {
                            case 0:
                                tlpPropagandaLinha4.ColumnStyles[0] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                
                                tlpPropagandaLinha4.ColumnStyles[1] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                pictureBox26.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox26.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 1:
                                tlpPropagandaLinha4.ColumnStyles[1] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha4.ColumnStyles[2] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha4.ColumnStyles[3] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox27.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox27.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 2:
                                tlpPropagandaLinha4.ColumnStyles[3] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha4.ColumnStyles[4] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha4.ColumnStyles[5] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox28.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox28.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 3:
                                tlpPropagandaLinha4.ColumnStyles[5] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha4.ColumnStyles[6] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha4.ColumnStyles[7] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox29.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox29.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 4:
                                tlpPropagandaLinha4.ColumnStyles[7] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha4.ColumnStyles[8] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha4.ColumnStyles[9] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox30.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox30.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 5:
                                tlpPropagandaLinha4.ColumnStyles[9] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha4.ColumnStyles[10] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha4.ColumnStyles[11] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox31.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox31.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 6:
                                tlpPropagandaLinha4.ColumnStyles[11] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha4.ColumnStyles[12] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha4.ColumnStyles[13] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox32.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox32.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                            case 7:
                                tlpPropagandaLinha4.ColumnStyles[13] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha4.ColumnStyles[14] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                pictureBox33.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox33.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2), 3, (int)((20 - listaPropaganda[contPropagandas].Altura) / 2));
                                break;
                        }
                        largDisp -= listaPropaganda[contPropagandas].Largura;
                        contPropagandas++;
                    }
                }
            }


        }




        private void btnPropagandas_Click(object sender, EventArgs e)
        {
            Expandir("Propagandas");
            PopularGridPropagandas();
            LoadPropagandas();
        }

        private void btnAddPropaganda_Click(object sender, EventArgs e)
        {
            dtoPropaganda = new DTOPropaganda();
            dtoPropaganda.PropagandaID = 0;
            btnProcurarImagem.Enabled = true;
            btnProcurarImagem_Click(null, null);
        }

        private void btnUpPropaganda_Click(object sender, EventArgs e)
        {
            int index = 0;
            if (dgvPropagandas.CurrentCellAddress.Y > 0)
            {

                index = dgvPropagandas.CurrentCellAddress.Y - 1;
                bllPropaganda.AlterarIndice(Int32.Parse(dgvPropagandas[0, dgvPropagandas.CurrentCellAddress.Y].Value.ToString()), Int32.Parse(dgvPropagandas[0, dgvPropagandas.CurrentCellAddress.Y - 1].Value.ToString()));


                PopularGridPropagandas();
                LoadPropagandas();
                dgvPropagandas.CurrentCell = dgvPropagandas.Rows[index].Cells[0];
            }
        }

        private void btnDownPropaganda_Click(object sender, EventArgs e)
        {
            int index = 0;
            if (dgvPropagandas.CurrentCellAddress.Y < dgvPropagandas.Rows.Count - 1)
            {
                index = dgvPropagandas.CurrentCellAddress.Y + 1;
                bllPropaganda.AlterarIndice(Int32.Parse(dgvPropagandas[0, dgvPropagandas.CurrentCellAddress.Y].Value.ToString()), Int32.Parse(dgvPropagandas[0, dgvPropagandas.CurrentCellAddress.Y + 1].Value.ToString()));


                PopularGridPropagandas();
                LoadPropagandas();
                dgvPropagandas.CurrentCell = dgvPropagandas.Rows[index].Cells[0];

            }
        }

        private void btnExcluirPropaganda_Click(object sender, EventArgs e)
        {
            if (dgvPropagandas.CurrentCellAddress.Y >= 0)
            {
                if (new frmMessageBox().Show("Tem certeza que deseja Excluir esta Propaganda permanentemente?", "Aviso", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes)
                {
                    bllPropaganda.Excluir(Int32.Parse(dgvPropagandas[0, dgvPropagandas.CurrentCellAddress.Y].Value.ToString()));
                    PopularGridPropagandas();
                    LoadPropagandas();
                    txtNomePropaganda.Clear();
                    pcbImagem.Image = null;
                }
            }
        }

        private void toolStripButtonSair_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void dgvPropagandas_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            dtoPropaganda.PropagandaID = Int32.Parse(dgvPropagandas[0, dgvPropagandas.CurrentCellAddress.Y].Value.ToString());
            dtoPropaganda = bllPropaganda.BuscarPropagandaID(dtoPropaganda.PropagandaID);
            txtNomePropaganda.Text = dtoPropaganda.Nome;
            pcbImagem.Image = dtoPropaganda.Imagem;
            numAltura.Value = dtoPropaganda.Altura;
            numLargura.Value = dtoPropaganda.Largura;
            Application.DoEvents();
        }

        private void btnEditarPropaganda_Click(object sender, EventArgs e)
        {
            btnSalvarPropagandas.Enabled = true;
            txtNomePropaganda.Enabled = true;

            dtoPropaganda.PropagandaID = 0;
            btnProcurarImagem.Enabled = true;
            dgvPropagandas_CellClick(null, null);
        }

        private void btnBemVindo_Click(object sender, EventArgs e)
        {
            DTOBemVindo dtobemVindo = new BLLBemVindo().Exibir();
            Expandir("BemVindo");
            lblFuncionario.Text = BLLUtilitarios.FuncionarioLogado;
            numTempoBemVindo.Value = dtobemVindo.Tempo;
            ckbExibirSaudacao.Checked = dtobemVindo.Exibir;
        }

        private void btnSalvarBemVindo_Click(object sender, EventArgs e)
        {
            DTOBemVindo dtoBemVindo = new DTOBemVindo();
            dtoBemVindo.Tempo = (int)(numTempoBemVindo.Value);
            dtoBemVindo.Exibir = ckbExibirSaudacao.Checked;
            new BLLBemVindo().Atualizar(dtoBemVindo);
            new frmMessageBox().Show("Suas Alterações Foram salvas com sucesso.", "Salvar", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

    }
}
